require("lfs")


local function getExtension(str)
    return str:match("(.+)%.(%w+)$")
end
--[[
    getFileList的参数说明:
    path:读取的文件夹
    postfix:过滤的后缀名,如果不配置,代表所有文件都匹配
--]]
function getFileList(path,postfix)
    local base_path = lfs.currentdir()
    local path_t = {}
    path = base_path .."\\" ..  path
    for filename in lfs.dir(path) do
        if filename~="." and filename~=".." then
            local filepath = path..'\\'..filename
            local fileattr = lfs.attributes(filepath)
            if fileattr.mode == "file" then
                --print(filename)
                --后缀名是jpg格式,则可以去转换成rgb数据
                
                local pre_filename,extension_name = getExtension(filename)
                
                if extension_name ~= nil then
                    if postfix == nil or extension_name == postfix  then
                        table.insert(path_t,{path=filepath,filename=pre_filename,extension=extension_name,name=filename})
                    end
                end
            end
        end
    end
    return path_t
end